import apiClient from './apiClient';
import returnModel from '../../model/common/returnModel';

export abstract class clientBase {
  public readonly client: apiClient;

  constructor() {
    this.client = new apiClient();
  }

  public buildSuccessResult<T>(data?: T, msg?: string): returnModel<T> {
    let r = new returnModel<T>();
    r.success = true;
    r.msg = msg;
    r.data = data;
    return r;
  }

  public buildFailedResult<T>(msg?: string): returnModel<T> {
    let r = new returnModel<T>();
    if (msg)
      r.msg = msg;
    r.success = false;
    return r;
  }

  public buildExceptionResult<T>(exc: Error): returnModel<T> {
    let r = new returnModel<T>();
    r.msg = exc.message;
    r.success = false;
    return r;
  }
}